package cn.chenc.framework.core.util;

import org.apache.commons.lang3.ArrayUtils;
import org.springframework.util.CollectionUtils;

import java.util.Collection;
import java.util.Map;

/**
 * 　@description: TODO
 * 　@author secret
 * 　@date 2021/6/5 23:17
 *
 */
public class AssertUtil {

    public static void isTrue(boolean expression, String message) {
        if (!expression) {
            throw new IllegalArgumentException(StringUtils.format(message, new Object[0]));
        }
    }

    public static void isFalse(boolean expression, String message) {
        isTrue(!expression, message);
    }

    public static void isNull(Object object, String message) {
        isTrue(object == null, message);
    }

    public static void notNull(Object object, String message) {
        isTrue(object != null, message);
    }

    public static void notEmpty(Collection<?> collection, String message) {
        isTrue(!CollectionUtils.isEmpty(collection), message);
    }

    public static void notEmpty(Map<?, ?> map, String message) {
        isTrue(!CollectionUtils.isEmpty(map),message);
    }

    public static void notEmpty(Object[] array, String message) {
        isTrue(ArrayUtils.isNotEmpty(array), message);
    }

}
